package com.yxhl.zoume.core.tripsmgmt.ui.fragment.tripsdetail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.yxhl.protobuf.BizOrder;
import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.JudgeEntry;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.protobuf.OrderPayStatus;
import com.yxhl.protobuf.OrderRideStatus;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.CheckBoxLayout;
import com.yxhl.zoume.common.ui.fragment.BaseFragment;
import com.yxhl.zoume.core.car.fragment.common.CancelCarOrderFeedbackFragment;
import com.yxhl.zoume.core.car.model.PayResultEvent;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.func.appraisal.model.CommentOnDriverEvent;
import com.yxhl.zoume.core.func.appraisal.ui.activity.AppraisalConfirmActivity;
import com.yxhl.zoume.core.func.pay.model.CarPaymentEntrance;
import com.yxhl.zoume.core.specialcar.model.CarPaymentInfo;
import com.yxhl.zoume.core.tripsmgmt.info.CommentEntrance;
import com.yxhl.zoume.core.tripsmgmt.presenter.detail.DetailTripContainerPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.unit.CancelOrderPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.unit.CommentOnDriverPresenter;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TripDetailContainerActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderFromDialogEvent;
import com.yxhl.zoume.core.tripsmgmt.view.detail.DetailOrderView;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CancelOrderView;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.trip.DaggerTripComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.trip.TripModule;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.StringUtils;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.functions.Action1;

import static com.yxhl.protobuf.OrderPayStatus.PAY_CANCEL;

/**
 * 项目名称：Ferrari
 * Created by menggod on 16/12/13 .
 */

public class ExpressCarTripDetailFragment extends BaseFragment implements DetailOrderView ,CancelOrderView {

    //头部
    @BindView(R.id.rl_include_trip_detail_station_info)
    RelativeLayout mStationInfoRl;
    @BindView(R.id.iv_include_trip_detail_station_info_icon)
    ImageView mStationInfoIconIv;
    @BindView(R.id.tv_include_trip_detail_station_info_start)
    TextView mStationInfoStartTv;
    @BindView(R.id.tv_include_trip_detail_station_info_clock)
    TextView mStationInfoClockTv;
    @BindView(R.id.tv_include_trip_detail_station_info_date)
    TextView mStationInfoDateTv;
    @BindView(R.id.tv_include_trip_detail_station_info_destination)
    TextView mStationInfoDestinationTv;
    //乘客信息栏
    @BindView(R.id.tv_official_car_trip_first_row_content)
    TextView mFirstRowContentTv;
    @BindView(R.id.tv_official_car_trip_second_row_content)
    TextView mSecondRowContentTv;
    @BindView(R.id.iv_official_car_trip_info_map)
    ImageView mTripInfoMapIv;

    //订单信息栏
    @BindView(R.id.tv_include_trip_detail_order_id_content)
    TextView mOrderIdContentTv;
    @BindView(R.id.tv_include_trip_detail_order_create_time_content)
    TextView mOrderCreateTimeContentTv;
    @BindView(R.id.tv_include_trip_detail_order_status_content)
    TextView mOrderStatusContentTv;
    @BindView(R.id.tv_include_trip_detail_get_in_content)
    TextView mGetInContentTv;
    @BindView(R.id.tv_include_trip_detail_get_off_content)
    TextView mGetOffContentTv;
    //评价司机栏
    @BindView(R.id.rl_include_trip_detail_judge_info)
    RelativeLayout mJudgeInfoRl;
    @BindView(R.id.cbl_include_trip_detail_judge)
    CheckBoxLayout mJudgeCbl;
    @BindView(R.id.tv_include_trip_detail_judge)
    TextView mJudgeTv;
    @BindView(R.id.ll_server_comment)
    LinearLayout mLlServerComment;  //服务评价
    //底部信息
    //底栏
    @BindView(R.id.frame_express_car_bottom_container)
    FrameLayout bottomContainerFrame;
    //支付
    @BindView(R.id.tv_express_car_bottom_payment)
    TextView mTvExpressCarBottomPayment;
    @BindView(R.id.ll_express_car_bottom_payment)
    LinearLayout mLlExpressCarBottomPayment;
    //取消订单
    @BindView(R.id.tv_express_car_bottom_cancel_order)
    TextView mTvExpressCarBottomCancelOrder;
    @BindView(R.id.ll_express_car_bottom_cancel_order)
    LinearLayout mLlExpressCarBottomCancelOrder;

    //优惠券
    @BindView(R.id.ll_trip_detail_coupon)
    LinearLayout mLlTripDetailCoupon;  //详情优惠
    @BindView(R.id.tv_trip_detail_coupon_original)
    TextView mTvTripDetailCouponOriginal;  //原价
    @BindView(R.id.tv_trip_detail_coupon_discount)
    TextView mTvTripDetailCouponDiscount;  //差价
    @BindView(R.id.iv_trip_detail_payment_arrow)
    ImageView mIvTripDetailPaymentArrow;  // 展开箭头

    @BindView(R.id.view_include_trip_detail_order_payment_fee)
    View orderPaymentFeeTopLine;
    @BindView(R.id.ll_include_trip_detail_order_payment_fee)  //价格条目
    LinearLayout orderPaymentFeeLl;
    @BindView(R.id.tv_include_trip_detail_order_payment_fee_content)
    TextView orderPaymentFeeContentTv;

    private static final String EXPRESS_CAR_ARGUMENT = "EXPRESS_CAR_ARGUMENT";
    private BizOrder mBizOrder;
    private MaterialDialog mMaterialDialog;
    /**
     * 取消订单等待对话框
     */
    private MaterialDialog mDialogForWaitingCancel;
    private static final String TAG = "ExpressCarTripDetailFragment";

    @Inject
    DetailTripContainerPresenter mDetailTripContainerPresenter;
    @Inject
    CancelOrderPresenter mCancelOrderPresenter;
    @Inject
    CommentOnDriverPresenter mCommentOnDriverPresenter;

    public static ExpressCarTripDetailFragment newInstance(BizOrder bizOrder) {
        Bundle args = new Bundle();
        args.putSerializable(EXPRESS_CAR_ARGUMENT, bizOrder);
        ExpressCarTripDetailFragment fragment = new ExpressCarTripDetailFragment();
        fragment.setArguments(args);
        return fragment;
    }
    private void parseArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mBizOrder = (BizOrder) arguments.getSerializable(EXPRESS_CAR_ARGUMENT);
        }
    }

    private void onRxBusEvent() {

        getSubscription().add(toSubscription(CancelTripOrderFromDialogEvent.class,
                new Action1<CancelTripOrderFromDialogEvent>() {
                    @Override
                    public void call(CancelTripOrderFromDialogEvent cancelTripOrderFromDialogEvent) {
                        if (mCancelOrderPresenter != null) {
                            mCancelOrderPresenter.cancelOrder(mBizOrder.getOrderSerial());
                        }
                    }
                }
        ));


        //取消订单
        getSubscription().add(toSubscription(CancelTripOrderEvent.class,
                new Action1<CancelTripOrderEvent>() {
                    @Override
                    public void call(CancelTripOrderEvent cancelTripOrderEvent) {
                        if (mBizOrder != null) {
                            OrderRideStatus rideStatus = mBizOrder.getRideStatus();
                            switch (rideStatus) {
                                case UN_SEND:
                                    mActivity.finish();
                                    break;
                                default:
                                    String orderSerial = mBizOrder.getOrderSerial();
                                    mDetailTripContainerPresenter.getDetailTripOrder(orderSerial);
                            }
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        onRxBusEvent();
                    }
                }
        ));
        //评价司机
        getSubscription().add(toSubscription(
                CommentOnDriverEvent.class,
                new Action1<CommentOnDriverEvent>() {
                    @Override
                    public void call(CommentOnDriverEvent commentOnDriverEvent) {
                        int point = commentOnDriverEvent.getPoint();
                        CommentEntrance commentEntrance = commentOnDriverEvent.getCommentEntrance();

                        mJudgeTv.setVisibility(View.INVISIBLE);
                        mJudgeInfoRl.setVisibility(View.VISIBLE);
                        showJudePoint(point);

                    }
                }
        ));


        getSubscription().add(toSubscription(
                PayResultEvent.class,
                new Action1<PayResultEvent>() {
                    @Override
                    public void call(PayResultEvent payResultEvent) {
                        switch (payResultEvent.getPayStatus()) {
                            case STATUS_ENUM_TRUE: {
                          //      mJudgeInfoRl.setVisibility(View.VISIBLE);
                                mDetailTripContainerPresenter.getDetailTripOrder(mBizOrder.getOrderSerial());
                                break;
                            }
                        }
                    }
                }
        ));


    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        parseArguments();
        onRxBusEvent();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        ViewCompat.setTransitionName(mStationInfoRl, UIConstants.TripContainer.TRIP_DETAIL_SHARE_ELEMENT);
        mDetailTripContainerPresenter.attachView(this);
        mCancelOrderPresenter.attachView(this);
        mCommentOnDriverPresenter.attachView(this);
        initializeShow(mBizOrder);
        bindData(mBizOrder);
        ButterKnife.bind(this, view);
        return view;
    }
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mDetailTripContainerPresenter.getDetailTripOrder(mBizOrder.getOrderSerial());
    }

    @Override
    public void onStart() {
        super.onStart();
        mLlServerComment.setClickable(false);
        setCommentItemEnable();

    }

    private void setCommentItemEnable() {
        if (View.VISIBLE == mJudgeCbl.getVisibility()) {
            mLlServerComment.setClickable(true);
        }
    }



    /**
     * 去支付
     *
     * @param v
     */
    @OnClick(R.id.ll_express_car_bottom_payment)
    public void onBottomPaymentClick(View v) {
        CarPaymentInfo specialCarPaymentInfo = getSpecialCarPaymentInfo(mBizOrder);
        getAppComponent().navigator().navigateToSpecialCarPayment(getActivity(), specialCarPaymentInfo);

    }


    private CarPaymentInfo getSpecialCarPaymentInfo(BizOrder bizOrder) {
        CarPaymentInfo specialCarPaymentInfo = new CarPaymentInfo();
        CarPaymentEntrance currentEntrance = null;
        OrderBizType bizType = bizOrder.getBizType();
        switch (bizType){
            case SPECIAL_BUS_TIME:
                currentEntrance = CarPaymentEntrance.CAR_PAYMENT_ENTRANCE_EXPRESS_CAR_TIME;
                break;
            case SPECIAL_BUS_WAY:
                currentEntrance = CarPaymentEntrance.CAR_PAYMENT_ENTRANCE_EXPRESS_CAR_WAY;
                break;
        }

        specialCarPaymentInfo.setOrderId(bizOrder.getOrderSerial())
                .setCarPaymentEntrance(currentEntrance)
                .setTotalFee(bizOrder.getTotalFee() + "")
                .setBizType(bizOrder.getBizTypeValue())
                .setDriverName(bizOrder.getDriverName())
                .setPlateNumber(bizOrder.getVehicleNo())
                .setHistoryScore(Double.valueOf((TextUtils.isEmpty(bizOrder.getAvgDriverPoint())) ? "4" : bizOrder.getAvgDriverPoint()));

        return specialCarPaymentInfo;
    }

    /**
     * 取消订单
     *
     * @param view
     */
    @OnClick(R.id.ll_express_car_bottom_cancel_order)
    public void onBottomCancelOrder(View view) {
        ((TripDetailContainerActivity) mActivity).replaceFragment(
                R.id.frame_activity_trip_detail_container,
                CancelCarOrderFeedbackFragment.newInstance(mBizOrder.getOrderSerial()),
                true
        );
    }

    /**
     * 进入地图
     */
    @OnClick(R.id.iv_official_car_trip_info_map)
    void onTripInfoMapClick() {
        getAppComponent().navigator().navigateToExpressCarScheduleActivity(mActivity, mBizOrder.getOrderSerial());
    }

    /**
     * 去评价
     */
    @OnClick(R.id.tv_include_trip_detail_judge)
    void onJudgeDriverClick() {
        AppraisalDriverInfo driverInfo = getAppraisalDriverInfo();
        getAppComponent().navigator().navigateToAppraisal(mActivity, driverInfo);
    }

    private AppraisalDriverInfo getAppraisalDriverInfo() {
        AppraisalDriverInfo driverInfo = new AppraisalDriverInfo();
        driverInfo.setOrderId(mBizOrder.getOrderSerial())
                .setDriverName(mBizOrder.getDriverName())
                .setHistoryScore(Double.valueOf((TextUtils.isEmpty(mBizOrder.getAvgDriverPoint())) ? "4" : mBizOrder.getAvgDriverPoint()))
                .setPlateNumber(mBizOrder.getVehicleNo());
        return driverInfo;
    }

    /**
     * 跳转到评价点击
     */
    @OnClick(R.id.ll_server_comment)
    public void onClick() {
        navigateToAppraisalResult(mActivity, getAppraisalDriverInfo());
    }

    /**
     * 跳转到评价结果页面
     *
     * @param activity
     * @param driverInfo
     */
    private void navigateToAppraisalResult(Activity activity, AppraisalDriverInfo driverInfo) {
        Intent intent = AppraisalConfirmActivity.getCallingIntent(activity, driverInfo);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);

    }


    /**
     * 初始化UI展示
     *
     * @param bizOrder
     */
    private void initializeShow(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        OrderBizType bizType = bizOrder.getBizType();

        //改变顶部信息
        exchangeStationInfoIcon(bizType);
        //地图图标样式
        exchangeTripMapStyle(payStatus);

        //司机评价栏
        exchangeJudgeDriverStyle(payStatus);

        //改变底部信息栏信息
        exchangeBottomBarStyle(bizOrder);


    }




    private void bindData(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        OrderRideStatus rideStatus = bizOrder.getRideStatus();
        //头部站点信息
        setStartStation(bizOrder.getStart());
        setDestination(bizOrder.getDestination());
        setStartTimeAndData(bizOrder.getGmtDepart());


        String driverInfo = bizOrder.getVehicleNo() + StringUtils.getCalledName(bizOrder.getDriverName());
        setTripFirstRowContent(driverInfo, payStatus);

        setTripSecondRowContent(bizOrder.getMobile());     //乘车人


        //订单状态信息
        setOrderId(bizOrder.getOrderSerial());
        setOrderStatus(payStatus, rideStatus,bizOrder);
        setGmtCreate(bizOrder.getGmtCreate());
        //上车时间
        setGetInTime(bizOrder.getGmtStart(), rideStatus, payStatus);
        //下车时间
        setGetOffTime(bizOrder.getGmtEnd());

        //评论
        JudgeEntry judgeEntry = bizOrder.getJudge();
        setDriverJudge(judgeEntry);

        //coupon
        setCouponInfo(bizOrder);
    }

    private void setCouponInfo(BizOrder bizOrder) {
        mTvTripDetailCouponOriginal.setText("¥" + bizOrder.getOrderTotalFee());
        mTvTripDetailCouponDiscount.setText("－¥" + bizOrder.getDiscountFee());

    }

    /**
     * 改变行程详情类型图标
     *
     * @param bizType
     */
    private void exchangeStationInfoIcon(OrderBizType bizType) {
        switch (bizType) {
            case SPECIAL_BUS_WAY:
                mStationInfoIconIv.setImageResource(R.drawable.ic_special_bus_way);
                break;
            case SPECIAL_BUS_TIME:
                mStationInfoIconIv.setImageResource(R.drawable.ic_special_bus_time);
                break;
        }
    }


    private void exchangeJudgeDriverStyle(OrderPayStatus payStatus) {
        switch (payStatus) {
            case ORDER_FINISH:
                mJudgeInfoRl.setVisibility(View.VISIBLE);
                break;
            default:
                mJudgeInfoRl.setVisibility(View.GONE);
                break;
        }
    }

    private void exchangeBottomBarStyle(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        OrderRideStatus rideStatus = bizOrder.getRideStatus();
        switch (rideStatus) {
            case UN_SEND://未派车
                bottomContainerFrame.setVisibility(View.VISIBLE);
                mLlExpressCarBottomPayment.setVisibility(View.GONE);
                mLlExpressCarBottomCancelOrder.setVisibility(View.VISIBLE);
                break;
            case UN_TAKEN://未上车
                bottomContainerFrame.setVisibility(View.VISIBLE);
                mLlExpressCarBottomPayment.setVisibility(View.GONE);
                mLlExpressCarBottomCancelOrder.setVisibility(View.VISIBLE);
                break;
            case TAKEN://已上车
            case PART_TAKEN: //部分上车
                mLlExpressCarBottomCancelOrder.setVisibility(View.GONE);
                break;
            case ARRIVED://已到站
            case PART_ARRIVED: //部分已到站
                mLlExpressCarBottomCancelOrder.setVisibility(View.GONE);
                break;
            case RIDE_INVALID://未乘坐
            case DROP: //已放弃
                mLlExpressCarBottomCancelOrder.setVisibility(View.GONE);
                break;
            default:
        }

        switch (payStatus) {
            case CREATED:
                bottomContainerFrame.setVisibility(View.VISIBLE);
                break;
            default:
                bottomContainerFrame.setVisibility(View.GONE);
        }
    }

    private void exchangeTripMapStyle(OrderPayStatus payStatus) {
        switch (payStatus) {
            case PAID:
                mTripInfoMapIv.setClickable(false);
                mTripInfoMapIv.setImageResource(R.drawable.ic_bukechakanditu);
                break;
            case CREATED:
            case PART_FINISH:
            case OPS_PART_REFUND:
                mTripInfoMapIv.setClickable(true);
                mTripInfoMapIv.setImageResource(R.drawable.ic_kechakanditu);
                break;
            default:
                mTripInfoMapIv.setClickable(false);
                mTripInfoMapIv.setImageResource(R.drawable.ic_bukechakanditu);
                break;
        }
    }

    /**
     * 显示出发地
     *
     * @param station
     */
    private void setStartStation(String station) {
        if (!TextUtils.isEmpty(station)) {
            mStationInfoStartTv.setText(station);
        } else {
            mStationInfoStartTv.setText("");
        }
    }

    /**
     * 显示目的地
     *
     * @param station
     */
    private void setDestination(String station) {
        if (!TextUtils.isEmpty(station)) {
            mStationInfoDestinationTv.setText(station);
        } else {
            mStationInfoDestinationTv.setText("—— ——");
        }
    }

    /**
     * 显示出发时刻和日期
     *
     * @param timeStamp
     */
    private void setStartTimeAndData(String timeStamp) {
        if (!TextUtils.isEmpty(timeStamp)) {
            String[] strings = timeStamp.split(" ");
            if (strings != null) {
                mStationInfoDateTv.setText(strings[0]);
                mStationInfoClockTv.setText(strings[1]);
            }
        } else {
            mStationInfoDateTv.setText("-");
            mStationInfoClockTv.setText("-");
        }
    }

    private void setTripFirstRowContent(String info) {
        if (!TextUtils.isEmpty(info)) {
            mFirstRowContentTv.setText(info);
        } else {
            mFirstRowContentTv.setText("车辆调派中");
        }
    }

    private void setTripFirstRowContent(String info, OrderPayStatus payStatus) {
        if (!TextUtils.isEmpty(info)) {
            mFirstRowContentTv.setText(info);
        } else {
            if (payStatus == OrderPayStatus.PAY_CANCEL) {
                mFirstRowContentTv.setText("—— ——");
            } else {
                mFirstRowContentTv.setText("车辆调派中");
            }
        }
    }

    private void setTripSecondRowContent(String passengerMobile) {
        if (!TextUtils.isEmpty(passengerMobile)) {
            mSecondRowContentTv.setText(passengerMobile);
        }
    }

    /**
     * 显示订单编号
     *
     * @param orderId
     */
    private void setOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            mOrderIdContentTv.setText(orderId);
        }
    }


    /**
     * 显示行程状态
     *
     * @param payStatus
     */
    private void setOrderStatus(OrderPayStatus payStatus, OrderRideStatus rideStatus, BizOrder bizOrder) {

        String rideStatusStr = getTripStatusForExpressCar(rideStatus, payStatus, bizOrder);
        mOrderStatusContentTv.setText(rideStatusStr);
    }

    private String getTripStatusForExpressCar(OrderRideStatus rideStatus, OrderPayStatus payStatus, BizOrder bizOrder) {
        String tripStatusStr;
        switch (rideStatus) {
            case UN_SEND://未派车
                tripStatusStr = getString(R.string.route_detail_no_charter);
                break;
            case UN_TAKEN://未上车
                tripStatusStr = getString(R.string.route_detail_wait_charter);
                break;
            case TAKEN://已上车
            case PART_TAKEN: {//部分上车

                switch (payStatus){
                    case OPS_SEND_BILL:
                        tripStatusStr = "等待支付";
                        showTotalFee(bizOrder.getTotalFee());
                        showPayment(bizOrder);
                        break;
                    case PAID:
                        tripStatusStr = "已支付";
                        mJudgeInfoRl.setVisibility(View.VISIBLE);
                        showTotalFee(bizOrder.getTotalFee());
                        setDriverJudge(bizOrder.getJudge());
                        break;
                    default:
                        tripStatusStr = "行程中";
                        bottomContainerFrame.setVisibility(View.GONE);
                        mLlExpressCarBottomCancelOrder.setVisibility(View.GONE);

                        break;
                }

                break;
            }
            case ARRIVED://已到站
            case PART_ARRIVED: //部分已到站

                switch (payStatus){
                    case  PAID:
                        tripStatusStr = "已支付";
                        break;
                    default:
                        tripStatusStr = getString(R.string.route_detail_finish_charter);
                        break;
                }

                mJudgeInfoRl.setVisibility(View.VISIBLE);
                showTotalFee(bizOrder.getTotalFee());
                setDriverJudge(bizOrder.getJudge());

                break;
            case RIDE_INVALID://未乘坐
            case DROP: //已放弃
                tripStatusStr = getString(R.string.route_detail_cancel_charter);
                break;
            default:
                tripStatusStr = "";
        }
        return tripStatusStr;
    }

    /**
     * 去支付
     *
     * @param bizOrder
     */
    private void showPayment(BizOrder bizOrder) {
        bottomContainerFrame.setVisibility(View.VISIBLE);
        mLlExpressCarBottomPayment.setVisibility(View.VISIBLE);
        mBizOrder = bizOrder;
    }


    /**
     * 显示总费用
     *
     * @param fee
     */
    private void showTotalFee(double fee) {
        orderPaymentFeeLl.setVisibility(View.VISIBLE);
        orderPaymentFeeTopLine.setVisibility(View.VISIBLE);
        if (fee >= 0) {
            orderPaymentFeeContentTv.setText(fee + "元");
        } else {
            orderPaymentFeeContentTv.setText("");
        }
    }


    /**
     * 显示下单时间
     *
     * @param time
     */
    private void setGmtCreate(String time) {
        if (!TextUtils.isEmpty(time)) {
            mOrderCreateTimeContentTv.setText(time);
        }
    }

    /**
     * 上车时间
     */
    private void setGetInTime(String time, OrderRideStatus rideStatus, OrderPayStatus payStatus) {
        if (rideStatus == OrderRideStatus.UN_SEND || payStatus == PAY_CANCEL|| rideStatus == OrderRideStatus.UN_TAKEN) {
            mGetInContentTv.setText("—— ——");
        } else {
            if (!TextUtils.isEmpty(time)) {
//                String[] strings = time.split(" ");
//                if (strings.length >= 2) {
                    mGetInContentTv.setText(time);
       //         }
            } else {
                mGetInContentTv.setText("—— ——");

            }
        }

    }

    /**
     * 上车时间
     */
    private void setGetInTime(String time) {
        if (!TextUtils.isEmpty(time)) {
            String[] strings = time.split(" ");
            if (strings.length >= 2) {
                mGetInContentTv.setText(strings[1]);
            }
        } else {
            mGetInContentTv.setText("—— ——");
        }
    }

    /**
     * 下车时间
     */
    private void setGetOffTime(String time) {
        if (!TextUtils.isEmpty(time)) {
            mGetOffContentTv.setText(time);
        } else {
            mGetOffContentTv.setText("—— ——");
        }
    }

    /**
     * 评价司机
     *
     * @param judgeEntry
     */
    private void setDriverJudge(JudgeEntry judgeEntry) {
        if (judgeEntry != null) {
            int judgePoint = judgeEntry.getJudgePoint();
            if (judgePoint > 0) {
                showJudePoint(judgePoint);
            } else {
                mJudgeCbl.setVisibility(View.INVISIBLE);
                mJudgeTv.setVisibility(View.VISIBLE);
            }
        } else {
            mJudgeCbl.setVisibility(View.INVISIBLE);
            mJudgeTv.setVisibility(View.VISIBLE);
        }
    }

    /**
     * 显示评价星星数
     *
     * @param judgePoint
     */
    private void showJudePoint(int judgePoint) {
        mJudgeCbl.setCheckedCount(judgePoint);
        mJudgeCbl.setClickable(false);
        mJudgeCbl.setVisibility(View.VISIBLE);
        mJudgeTv.setVisibility(View.INVISIBLE);
    }


    @Override
    public void renderDetailOrderOnSuccess(BizOrderResponse bizOrderResponse) {
        mBizOrder = bizOrderResponse.getOrderFieldses(0);
        initializeShow(mBizOrder);
        bindData(mBizOrder);
    }

    @Override
    public void renderDetailOrderOnFailure() {
        PromptUtils.showShort(getContext(), getString(R.string.net_error));
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        if (mMaterialDialog != null && mMaterialDialog.isShowing()) {
            mMaterialDialog.dismiss();
        }
    }
    @OnClick(R.id.ll_include_trip_detail_order_payment_fee)
    public void onDetailCuoponClick() {
        int visibility = mLlTripDetailCoupon.getVisibility();
        if (visibility == View.GONE) {
            mLlTripDetailCoupon.setVisibility(View.VISIBLE);
            triangleAnimationStart();
        } else {
            mLlTripDetailCoupon.setVisibility(View.GONE);
            triangleAnimationEnd();
        }

    }

    private void triangleAnimationStart() {
        RotateAnimation rotateAnimation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }

    private void triangleAnimationEnd() {
        RotateAnimation rotateAnimation = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }
    @Override
    protected void initializeInjector() {
        DaggerTripComponent
                .builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(mActivity))
                .tripModule(new TripModule())
                .build()
                .inject(this);
    }


    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_express_car_detail;
    }

    @Override
    protected void setupToolBar() {
        ((TripDetailContainerActivity) mActivity).setToolbarTitle(R.string.trip_detail_header_title);
    }

    @Override
    public void renderCancelOrderResult(boolean isCanceled) {
        if (isCanceled) {
            PromptUtils.showShort(mActivity, getString(R.string.cancel_order_success));
            RxBus.getInstance().send(new CancelTripOrderEvent(mBizOrder.getOrderSerial()));
            mActivity.finish();
        } else {
            PromptUtils.showLong(getActivity(), getString(R.string.trip_cancel_order_failure));
        }
    }

    @Override
    public void renderCancelError() {
        PromptUtils.showShort(mActivity, getString(R.string.trip_cancel_order_error));
    }

    @Override
    public void waitingForOrderCancel(boolean isWaiting) {
        if (isWaiting) {
            mDialogForWaitingCancel = new MaterialDialog.Builder(getActivity())
                    .content(R.string.dialog_waiting_canceling)
                    .progress(true, 0)
                    .canceledOnTouchOutside(false)
                    .show();
        } else {
            if (null != mDialogForWaitingCancel) {
                mDialogForWaitingCancel.dismiss();
            }
        }
    }
}
